package com.jzt.gateway.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzt.gateway.entity.AccountRegister;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 作者：lizw <br/>
 * 创建时间：2020/07/01 11:54 <br/>
 */
@Repository
@Mapper
public interface AccountRegisterDao extends BaseMapper<AccountRegister> {

    @Update("update account_register set user_agent_id=#{userAgentId} where one_id=#{oneId} and user_agent_id is null")
    int setUserAgentId(@Param("oneId") String oneId, @Param("userAgentId") String userAgentId);

    @Select("select * from account_register where user_agent_id is null and (next_retry_time is null or next_retry_time<#{now}) order by next_retry_time limit #{limit}")
    List<AccountRegister> findNeedRetry(@Param("now") Date now, @Param("limit") int limit);
}
